class eventBus {
	static eventStore: { [x: string]: Function[] }

	$emit(fncName: string, ...args: any) {
		const tempFncName = 'temp' + fncName,
			isOnceFnc = Object.keys(eventBus.eventStore).includes(tempFncName)
		eventBus.eventStore[isOnceFnc ? tempFncName : fncName].forEach(
			(handler: Function) => {
				handler(...args)
			},
		)
		if (isOnceFnc) delete eventBus.eventStore[tempFncName]
	}

	$on(fncName: string, callBack: Function) {
		if (!eventBus.eventStore[fncName]) eventBus.eventStore[fncName] = []
		eventBus.eventStore[fncName].push(callBack)
	}

	$once(fncName: string, callBack: Function) {
		const tempFncName = 'temp' + fncName
		eventBus.eventStore[tempFncName].push(callBack)
	}

	$off(fncName: string) {
		if (Object.keys(eventBus.eventStore).includes(fncName))
			delete eventBus.eventStore[fncName]
	}
}

class utilsClass extends eventBus {}

const utils = new utilsClass()

export default utils
